package com.csw.shuanfa.CodeImprove.CompleteFutureLinkedBlockingQueue.oldtest.ThreadAndBingFa;

import lombok.extern.slf4j.Slf4j;

@Slf4j
class RunnableDemo implements Runnable {
    private final String threadName;
    private Thread t;

    RunnableDemo(String name) {
        threadName = name;
        log.info("" + "Creating " + threadName);
    }

    @Override
    public void run() {
        log.info("" + "Running " + threadName);
        try {
            for (int i = 4; i > 0; i--) {
                log.info("" + "Thread: " + threadName + ", " + i);
                /* 让线程睡眠一会 */
                Thread.sleep(50);
            }
        } catch (InterruptedException e) {
            log.info("" + "Thread " + threadName + " interrupted.");
            Thread.currentThread().interrupt();
        }
        log.info("" + "Thread " + threadName + " exiting.");
    }

    public void start() {
        log.info("" + "Starting " + threadName);
        if (t == null) {
            t = new Thread(this, threadName);
            t.start();
        }
    }
}

class TestThread1 {

    public static void main(String[] args) {
        RunnableDemo runnableDemo = new RunnableDemo("Thread-1");
        runnableDemo.start();

        RunnableDemo runnableDemo1 = new RunnableDemo("Thread-2");
        runnableDemo1.start();
    }
}
